package cn.kgc.jinxin.clothesstore.service.impl;

import java.sql.Connection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.kgc.jinxin.clothesstore.dao.BaseDao;
import cn.kgc.jinxin.clothesstore.dao.GoodsDao;
import cn.kgc.jinxin.clothesstore.dao.impl.GoodsDaoImpl;
import cn.kgc.jinxin.clothesstore.entity.Goods;
import cn.kgc.jinxin.clothesstore.entity.PageInfo;
import cn.kgc.jinxin.clothesstore.service.GoodsService;

public class GoodsServiceImpl implements GoodsService {
	private GoodsDao goodsDao = new GoodsDaoImpl();

	@Override
	public Map<String, Object> findAllByPage(Integer currentPage, Integer PageSize) throws Exception {
		Map<String,Object> map = new HashMap<String,Object>();	
		Connection connection = null;
		try {
			connection = BaseDao.getConnection();
			map.put("totalRecord", this.goodsDao.selectTotalRecordByPage(connection));
			map.put("tlist", this.goodsDao.selectByPage(currentPage, PageSize, connection));
		} finally {
			BaseDao.close(connection, null, null);
		}
		return map;
	}

	@Override
	public void findAllByPage(PageInfo<Goods> goodsPageInfo) throws Exception {
		Connection connection = null;
		try {
			connection = BaseDao.getConnection();
			Integer totalRecord = this.goodsDao.selectTotalRecordByPage(goodsPageInfo,connection);
			goodsPageInfo.setTotalRecord(totalRecord);
			List<Goods> tlist = this.goodsDao.selectByPage(goodsPageInfo, connection);
			goodsPageInfo.setTlist(tlist);
		} finally {
			BaseDao.close(connection, null, null);
		}
		
	}
	
}



























